﻿using JNPF.Basics.Logic;
using JNPF.Basics.Models;
using JNPF.Utils;
using JNPF.Utils.Controller;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace JNPF.Basics.Controller
{
    /// <summary>
    /// 主页控制器
    /// 版 本：V3.0.0
    /// 版 权：引迈信息技术有限公司
    /// 作 者：管理员/admin
    /// 日 期：2020-11-02 11:49
    /// </summary>
    [Route("api/[controller]")]
    public class HomeController : BaseApiController
    {
        private FlowTaskBll flowTaskBll = new FlowTaskBll();
        private FlowDelegateBll flowDelegateBll = new FlowDelegateBll();
        private MessageBll messageBll = new MessageBll();
        private EmailBll emailBll = new EmailBll();

        #region GET
        /// <summary>
        /// 获取我的待办
        /// </summary>
        [HttpGet("FlowTodoCount")]
        public async Task<ResponseResult> GetFlowTodoCount()
        {
            var waitList = await flowTaskBll.GetWaitList();
            var flowList = await flowDelegateBll.GetList();
            var trialList = await flowTaskBll.GetTrialList();
            var data = new FlowTodoCountOutput()
            {
                toBeReviewed = waitList.list.Count(),
                entrust = flowList.list.Count(),
                flowDone = trialList.list.Count()
            };
            return Success(data);
        }

        /// <summary>
        /// 获取通知公告
        /// </summary>
        [HttpGet("Notice")]
        public async Task<ResponseResult> GetNotice()
        {
            List<NoticeOutput> list = new List<NoticeOutput>();
            (await messageBll.GetNoticeList()).list.ForEach(l =>
            {
                list.Add(new NoticeOutput()
                {
                    id = l.Id,
                    fullName = l.Title,
                    creatorTime = l.CreatorTime
                });
            });
            var data = new
            {
                list = list
            };
            return Success(data);
        }

        /// <summary>
        /// 获取未读邮件
        /// </summary>
        [HttpGet("Email")]
        public async Task<ResponseResult> GetEmail()
        {
            PageInput input = new PageInput();
            List<EmailOutput> list = new List<EmailOutput>();
            (await emailBll.GetUnreadList(input)).list.ForEach(l =>
            {
                list.Add(new EmailOutput()
                {
                    id = l.Id,
                    fullName = l.Subject,
                    creatorTime = l.CreatorTime
                });
            });
            var data = new
            {
                list = list
            };
            return Success(data);
        }

        /// <summary>
        /// 获取待办事项
        /// </summary>
        [HttpGet("FlowTodo")]
        public async Task<ResponseResult> GetFlowTodo()
        {
            PageInput input = new PageInput();
            List<FlowTodoOutput> list = new List<FlowTodoOutput>();
            (await flowTaskBll.GetWaitList(input)).list.ForEach(l =>
            {
                list.Add(new FlowTodoOutput()
                {
                    id = l.Id,
                    fullName = l.FlowName,
                    creatorTime = l.CreatorTime
                });
            });
            var data = new
            {
                list = list
            };
            return Success(data);
        }

        /// <summary>
        /// 获取我的待办事项
        /// </summary>
        [HttpGet("MyFlowTodo")]
        public async Task<ResponseResult> GetMyFlowTodo()
        {
            var data = new
            {
                list = new MyFlowTodoOutput()
                {
                    id = "11111111111",
                    enabledMark = 0,
                    content = "我的待办事项",
                    startTime = DateTime.Now,
                    endTime = DateTime.Now.AddDays(1)
                }
            };
            return Success(data);
        }
        #endregion
    }
}
